package com.benshou.bsoa.common.configuration;

import com.benshou.bsoa.common.validate.IValidator;
import jakarta.validation.Validator;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 参数校验配置类
 *
 * @author <a href="mailto:liuzhenbang@benshou.com">Liu Zhenbang</a>
 */
@Configuration
@RequiredArgsConstructor
public class ValidationConfiguration {

    private final Validator validator;

    /**
     * 注册自定义参数校验器
     *
     * @return IValidator
     */
    @Bean
    @ConditionalOnMissingBean(IValidator.class)
    public IValidator iValidator() {
        return new IValidator(this.validator);
    }
}
